﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace _EF调用SqlHelper
{
    public class SqlHelper
    {
        public static DataTable GetDataTable(string DbConn,CommandType cmdType,string sql,params SqlParameter[] para)
        {
            DataTable dt = new DataTable("Result");
            using (SqlConnection conn=new SqlConnection(DbConn))
            {
                conn.Open();
                using (SqlCommand cmd=new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandType = cmdType;
                    cmd.CommandText = sql;
                    cmd.Parameters.AddRange(para);
                    using (SqlDataAdapter sda=new SqlDataAdapter(cmd))
                    {
                        sda.Fill(dt);
                    }
                }
            }
            return dt;
        }
    }
}
